//小仓库 关于layout的设置
import { defineStore } from "pinia";
import { reqSearchMember, reqAddMember, reqDeleteMemberById, reqDeleteMemberByIds } from "@/api/member";
import { ElMessage } from "element-plus";

let useMemberStore = defineStore("MemberStore", {
    state: () => {
        return {
            memberList: [], // 列表
            total: 0, // 总数
        };
    },
    // 异步 | 逻辑的地方
    actions: {
        async searchMember(params: any) {
            // 调用接口
            let result = await reqSearchMember(params);
            if (result.code == 200) {
                if (result.data.list.length == 0) {
                    return false;
                } else {
                    this.memberList = result.data.list;
                    this.total = result.data.total;
                    return true;
                }
            }
        },
        async addMember(params: any) {
            var data1 = JSON.stringify(params);
            // 调用接口
            let result = await reqAddMember(data1);
            if (result.code == 200) {
                ElMessage.success("添加成功");
            } else {
                ElMessage.error("添加失败");
            }
        },
        async deleteMemberById(id: any) {
            // 调用接口
            let result = await reqDeleteMemberById(id);
            if (result.code == 200) {
                ElMessage.success("删除成功");
                return true;
            } else {
                ElMessage.error("删除失败");
                return false;
            }
        },
        async deleteMemberByIds(ids: any) {
            // 调用接口
            let result = await reqDeleteMemberByIds(ids);
            if (result.code == 200) {
                ElMessage.success("删除成功");
                return true;
            } else {
                ElMessage.error("删除失败");
                return false;
            }
        }
    },
    getters: {

    }
});

export default useMemberStore;